/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.invoice.header.service;

import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.invoice.header.service.dto.YxfpInvoiceHeaderDTO;
import com.jeeplus.invoice.header.domain.YxfpInvoiceHeader;
import com.jeeplus.invoice.header.mapper.YxfpInvoiceHeaderMapper;

import java.util.List;

/**
 * 抬头管理Service
 * @author 张如利
 * @version 2022-01-20
 */
@Service
@Transactional
public class YxfpInvoiceHeaderService extends ServiceImpl<YxfpInvoiceHeaderMapper, YxfpInvoiceHeader> {

	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	public YxfpInvoiceHeaderDTO findById(String id) {
		return baseMapper.findById ( id );
	}

	/**
	 * 自定义分页检索
	 * @param page
	 * @param queryWrapper
	 * @return
	 */
	public IPage <YxfpInvoiceHeaderDTO> findPage(Page <YxfpInvoiceHeaderDTO> page, QueryWrapper queryWrapper) {
		queryWrapper.eq ("a.del_flag", 0 ); // 排除已经删除
		return  baseMapper.findList (page, queryWrapper);
	}

	/**
	 * 根据客户ID获取抬头列表
	 * @param customerId
	 * @return
	 */
	public List<YxfpInvoiceHeaderDTO> findListByCustomerId(String customerId) {
		return  baseMapper.findListByCustomerId(customerId);
	}

	/**
	 * 设置该抬头为默认抬头
	 * @param id
	 */
	public void setDefaultInvoiceHeader(String id){
		baseMapper.setDefaultInvoiceHeader(id);
	}

	/**
	 * 根据客户ID设置所有抬头为非默认，设置客户默认前先调用该方法
	 * @param customerId
	 */
	public void setNotDefalutInvoiceHeaderByCustomerID(String customerId){
		baseMapper.setNotDefalutInvoiceHeaderByCustomerID(customerId);
	}

	/**
	 * 根据ID删除抬头
	 * @param id
	 */
	public void delInvoiceHeaderById(String id){
		baseMapper.delInvoiceHeaderById(id);
	}

	/**
	 * 根据客户Id获取默认抬头
	 * @param customerId
	 */
	public YxfpInvoiceHeaderDTO getDefaultHeaderByCustomerId(String customerId){
		return baseMapper.getDefaultHeaderByCustomerId(customerId);
	}

}
